package com.wannengbang.cloudleader.service.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.cloudleader.R;
import com.wannengbang.cloudleader.bean.PlanDetailsListBean;
import com.wannengbang.cloudleader.service.PlanDetailsActivity;
import com.wannengbang.cloudleader.utils.NumberFormatUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 信用卡列表
 */
public class PlanDetailsDailyListAdapter extends RecyclerView.Adapter<PlanDetailsDailyListAdapter.ViewHolder> {


    private List<PlanDetailsListBean.DataBean.DetailBean.DailyBean> listsBeans;
    private Context context;
    private onCallBackListener onCallBackListener;

    public void setOnCallBackListener(PlanDetailsDailyListAdapter.onCallBackListener onCallBackListener) {
        this.onCallBackListener = onCallBackListener;
    }

    public PlanDetailsDailyListAdapter(List<PlanDetailsListBean.DataBean.DetailBean.DailyBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_plan_details_daily_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        PlanDetailsListBean.DataBean.DetailBean.DailyBean dataBean = listsBeans.get(position);
        holder.tvId.setText("第" + (position + 1) + "笔消费");
        String amount = NumberFormatUtils.formatDouble(Double.parseDouble(dataBean.getAmount()) / 100);
        holder.tvMoney.setText(amount);
        //   "status": 1,            // 1待完成 2已完成
//        if (dataBean.getStatus() == 1) {
//            holder.tvCommit.setBackgroundResource(R.drawable.shape_rectangle_conner_theme15);
//            holder.tvCommit.setText("点击完成");
//            holder.tvCommit.setTextColor(context.getResources().getColor(R.color.white));
//        } else {
//            holder.tvCommit.setBackgroundResource(R.drawable.shape_rectangle_conner_gary15);
//            holder.tvCommit.setText("已完成");
//            holder.tvCommit.setTextColor(context.getResources().getColor(R.color.gary));
//        }


        holder.tvCommit.setOnClickListener(v -> {
            onCallBackListener.onCallBack(dataBean.getStatus(), dataBean.getId());
        });

    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_id)
        TextView tvId;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_commit)
        TextView tvCommit;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onCallBackListener {
        void onCallBack(int status, int id);
    }
}
